import 'package:flutter/material.dart';
import '/common/beans.dart';

// 主界面展示列表，点击跳转对应的界面

class HomePage extends StatelessWidget {
  final List<ScreenBean> pages;

  const HomePage({super.key, required this.pages});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Home Screen')),
      body: WillPopScope(
        onWillPop: () async {
          print("onWillPop");
          return false;
        },
        child: ListView.builder(
          itemCount: pages.length,
          itemBuilder: (context, index) {
            ScreenBean pageItem = pages[index];
            return ListTile(
              title: Text(pageItem.path),
              onTap: () => {_goToPage(context, pageItem)},
            );
          },
        ),
      ),
    );
  }

  _goToPage(BuildContext context, ScreenBean pageItem) {
    Navigator.push(
      context,
      MaterialPageRoute(
        builder: (context) => pageItem.hasTitle
            ? pageItem.screen
            : Scaffold(
                appBar: AppBar(
                  title: Text(pageItem.path),
                ),
                body: pageItem.screen),
      ),
    );
  }
}
